<?php
/* ========== ########## ========== ########## ========== ########## ========== */
/*                                                                              */
/*   WHMCS v4.1.2 NULLED R4 by FLIPMODE  [ BAD SYNTAX ]                         */
/*                                                                              */
/*                             INTERNAL BAD SYNTAX NULLED VERSION: 2.5.9.6 R4   */
/*                                                                              */
/*   ALL files have been analysed, cleaned and nulled of:                       */
/*     - Call Backs  (100%)                                                     */
/*     - Link Backs (95%)                                                       */
/*     - Licensing  (100%)                                                      */
/*     - Remote Links + URL's                                                   */
/*                                                                              */
/*   WHMCS v4.1.2 RELEASED: 4th November 2009                                   */
/*    -> FIRST v4.1.2 NULL R1: 19th November 2009                               */
/*    -> UPDATED v4.1.2 NULL R4: 27th November 2009                             */
/*                                                                              */
/*   TESTING + VERIFICATION::                                                   */
/*     Files Cleaned, Nulled, Checked, Verified By:                             */
/*      -> FLIPMODE!                                                            */
/*     Decoded By:                                                              */
/*      -> FLIPMODE! + Unknown Decoder                                          */
/*     Tested By:                                                               */
/*      -> FLIPMODE!, LeetWolf, and 12 Anonymous Users...                       */
/*     WHMCS 4.1.2 Supplied By:                                                 */
/*      -> WHM CompleteShit Coder @ WHMCS.com                                   */
/*                                                                              */
/*                                                                              */
/*   IMPORTANT NOTE::                                                           */
/*   PLEASE NOTE THIS IS FOR TRIAL PURPOSES ONLY!                               */
/*                          LIKE IT? THEN BUY IT!                               */
/*                                                                              */
/* ========== ########## ========== ########## ========== ########## ========== */

function getclientsdetails ($userid = '', $contactid = '')
{
	global $encryption_key;
	require ROOTDIR . '/includes/countries.php';
	if (!$userid)
	{
		$userid = $_SESSION['uid'];
	}

	$result = select_query ('tblclients', '', array ('id' => $userid));
	$data = mysql_fetch_array ($result);
	if ($contactid == 'billing')
	{
		$contactid = $data['billingcid'];
	}

	if ($contactid)
	{
		$result = select_query ('tblcontacts', '', array ('userid' => $userid, 'id' => $contactid));
		$data = array_merge ($data, mysql_fetch_array ($result));
		$data['id'] = $userid;
	}

	$details['id'] = $details['userid'] = $data['id'];
	$details['firstname'] = $data['firstname'];
	$details['lastname'] = $data['lastname'];
	$details['companyname'] = $data['companyname'];
	$details['email'] = $data['email'];
	$details['address1'] = $data['address1'];
	$details['address2'] = $data['address2'];
	$details['city'] = $data['city'];
	$details['state'] = $data['state'];
	$details['postcode'] = $data['postcode'];
	$details['country'] = $data['country'];
	$details['countryname'] = $countries[$data['country']];
	$details['phonenumber'] = $data['phonenumber'];
	$details['notes'] = $data['notes'];
	$details['password'] = $data['password'];
	$details['currency'] = $data['currency'];
	$details['cctype'] = $data['cardtype'];
	$details['cclastfour'] = $data['cardlastfour'];
	$details['securityqid'] = $data['securityqid'];
	$details['securityqans'] = decrypt ($data['securityqans']);
	$details['groupid'] = $data['groupid'];
	$details['status'] = $data['status'];
	$details['credit'] = $data['credit'];
	$details['taxexempt'] = $data['taxexempt'];
	$details['latefeeoveride'] = $data['latefeeoveride'];
	$details['overideduenotices'] = $data['overideduenotices'];
	$details['language'] = $data['language'];
	$lastlogin = $data['lastlogin'];
	$ipaddr = $data['ip'];
	$host = $data['host'];
	if ($lastlogin == '0000-00-00 00:00:00')
	{
		$details['lastlogin'] = 'No Login Logged';
	}
	else
	{
		$details['lastlogin'] = 'Date: ' . frommysqldate ($lastlogin, 'time') . ('' . '<br>IP Address: ' . $ipaddr . '<br>Host: ' . $host);
	}

	if (!function_exists ('getCustomFields'))
	{
		require dirname (__FILE__) . '/customfieldfunctions.php';
	}

	$customfields = getcustomfields ('client', '', $userid, 'on');
	$i = 1;
	foreach ($customfields as $value)
	{
		$details['customfields' . $i] = $value['value'];
		++$i;
	}

	$details['billingcid'] = $data['billingcid'];
	if ($contactid)
	{
		$details['domainemails'] = $data['domainemails'];
		$details['generalemails'] = $data['generalemails'];
		$details['invoiceemails'] = $data['invoiceemails'];
		$details['productemails'] = $data['productemails'];
		$details['supportemails'] = $data['supportemails'];
	}

	return $details;
}

function getclientsstats ($userid)
{
	global $CONFIG;
	global $currency;
	$currency = getcurrency ($userid);
	$stats = array ();
	$result = select_query ('tblinvoices', 'COUNT(*),SUM(total)', array ('userid' => $userid, 'status' => 'Paid'));
	$data = mysql_fetch_array ($result);
	$stats['numpaidinvoices'] = $data[0];
	$stats['paidinvoicesamount'] = formatcurrency ($data[1]);
	$result = select_query ('tblinvoices', 'COUNT(*),SUM(total)-COALESCE(SUM((SELECT SUM(amountin)-SUM(amountout) FROM tblaccounts WHERE tblaccounts.invoiceid=tblinvoices.id)),0)', array ('userid' => $userid, 'status' => 'Unpaid'));
	$data = mysql_fetch_array ($result);
	$stats['numdueinvoices'] = $data[0];
	$stats['dueinvoicesbalance'] = formatcurrency ($data[1]);
	$result = select_query ('tblinvoices', 'COUNT(*),SUM(total)', array ('userid' => $userid, 'status' => 'Cancelled'));
	$data = mysql_fetch_array ($result);
	$stats['numcancelledinvoices'] = $data[0];
	$stats['cancelledinvoicesamount'] = formatcurrency ($data[1]);
	$result = select_query ('tblinvoices', 'COUNT(*),SUM(total)', array ('userid' => $userid, 'status' => 'Refunded'));
	$data = mysql_fetch_array ($result);
	$stats['numrefundedinvoices'] = $data[0];
	$stats['refundedinvoicesamount'] = formatcurrency ($data[1]);
	$result = select_query ('tblaccounts', 'SUM(amountin-fees-amountout)', array ('userid' => $userid));
	$data = mysql_fetch_array ($result);
	$stats['income'] = formatcurrency ($data[0]);
	$result = select_query ('tblclients', 'credit', array ('id' => $userid));
	$data = mysql_fetch_array ($result);
	$stats['creditbalance'] = formatcurrency ($data['credit']);
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'domainstatus' => 'Active'));
	$data = mysql_fetch_array ($result);
	$stats['productsnumactive'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid));
	$data = mysql_fetch_array ($result);
	$stats['productsnumtotal'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'hostingaccount', 'domainstatus' => 'Active'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumactivehosting'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'hostingaccount'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumhosting'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'reselleraccount', 'domainstatus' => 'Active'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumactivereseller'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'reselleraccount'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumreseller'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'server', 'domainstatus' => 'Active'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumactiveservers'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'server'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumservers'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'other', 'domainstatus' => 'Active'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumactiveother'] = $data[0];
	$result = select_query ('tblhosting', 'COUNT(*)', array ('userid' => $userid, 'tblproducts.type' => 'other'), '', '', '', 'tblproducts ON tblhosting.packageid=tblproducts.id');
	$data = mysql_fetch_array ($result);
	$stats['productsnumother'] = $data[0];
	$result = select_query ('tbldomains', 'COUNT(*)', array ('userid' => $userid, 'status' => 'Active'));
	$data = mysql_fetch_array ($result);
	$stats['numactivedomains'] = $data[0];
	$result = select_query ('tbldomains', 'COUNT(*)', array ('userid' => $userid));
	$data = mysql_fetch_array ($result);
	$stats['numdomains'] = $data[0];
	$result = select_query ('tblquotes', 'COUNT(*)', array ('userid' => $userid, 'stage' => 'Accepted'));
	$data = mysql_fetch_array ($result);
	$stats['numacceptedquotes'] = $data[0];
	$result = select_query ('tblquotes', 'COUNT(*)', array ('userid' => $userid));
	$data = mysql_fetch_array ($result);
	$stats['numquotes'] = $data[0];
	$result = select_query ('tbltickets', 'COUNT(*)', array ('userid' => $userid, 'status' => array ('sqltype' => 'NEQ', 'value' => 'Closed')));
	$data = mysql_fetch_array ($result);
	$stats['numactivetickets'] = $data[0];
	$result = select_query ('tbltickets', 'COUNT(*)', array ('userid' => $userid));
	$data = mysql_fetch_array ($result);
	$stats['numtickets'] = $data[0];
	$result = select_query ('tblaffiliatesaccounts', 'COUNT(*)', array ('clientid' => $userid), '', '', '', 'tblaffiliates ON tblaffiliatesaccounts.affiliateid=tblaffiliates.id');
	$data = mysql_fetch_array ($result);
	$stats['numaffiliatesignups'] = $data[0];
	return $stats;
}

function getcountriesdropdown ($selected = '', $fieldname = 'country')
{
	global $countries;
	global $CONFIG;
	global $_LANG;
	if ($selected == '')
	{
		$selected = $CONFIG['DefaultCountry'];
	}

	$dropdowncode = '' . '<select name="' . $fieldname . '">';
	foreach ($countries as $countriesvalue1 => $countriesvalue2)
	{
		$dropdowncode .= '<option value="' . $countriesvalue1 . '"';
		if ($countriesvalue1 == $selected)
		{
			$dropdowncode .= ' selected="selected"';
		}

		$dropdowncode .= '>' . $countriesvalue2 . '</option>';
	}

	$dropdowncode .= '</select>';
	return $dropdowncode;
}

function checkdetailsarevalid ($firstname, $lastname, $email, $address1, $city, $state, $postcode, $phonenumber, $password1, $password2, $cccheck = '', $detailscheck = '')
{
	global $_LANG;
	global $errormessage;
	$errormessage = '';
	if (!trim ($firstname))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorfirstname'];
	}

	if (!trim ($lastname))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorlastname'];
	}

	if ((!trim ($email) AND !$cccheck))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerroremail'];
	}

	if ((!$cccheck AND trim ($email)))
	{
		$emaildomain = explode ('@', $email, 2);
		$emaildomain = $emaildomain[1];
		$result = select_query ('tblbannedemails', '', array ('domain' => $emaildomain));
		$data = mysql_fetch_array ($result);
		$banneddomainid = $data['id'];
		if ($banneddomainid)
		{
			update_query ('tblbannedemails', array ('count' => '+1'), array ('id' => $banneddomainid));
			$errormessage .= '<li>' . $_LANG['clientareaerrorbannedemail'];
		}

		if (!preg_match ('' . '/^([a-zA-Z0-9])+([a-zA-Z0-9\\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\\._-]+)+$/', $email))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerroremailinvalid'];
		}
		else
		{
			$query = 'email=\'' . mysql_real_escape_string ($email) . '\'';
			if (($cccheck OR $detailscheck))
			{
				$query .= ' AND id!=\'' . $_SESSION['uid'] . '\'';
			}

			$result = select_query ('tblclients', 'COUNT(*)', $query);
			$data = mysql_fetch_array ($result);
			if ($data[0])
			{
				$errormessage .= '<li>' . $_LANG['ordererroruserexists'];
			}
		}
	}

	if (!trim ($address1))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerroraddress1'];
	}

	if (!trim ($city))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorcity'];
	}

	if (!trim ($state))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorstate'];
	}

	if (!trim ($postcode))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorpostcode'];
	}
	else
	{
		if (ereg ('[^ A-Za-z0-9 -]', $postcode))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerrorpostcode2'];
		}
	}

	if (!trim ($phonenumber))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorphonenumber'];
	}
	else
	{
		if (ereg ('[^ .0-9-]', $phonenumber))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerrorphonenumber2'];
		}
	}

	if ($country == 'Select Country')
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorcountry'];
	}

	if (trim ($password1))
	{
		if (!trim ($password2))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerrorpasswordconfirm'];
		}
		else
		{
			if ($password1 != $password2)
			{
				$errormessage .= '<li>' . $_LANG['clientareaerrorpasswordnotmatch'];
			}
		}
	}

	run_hook ('ClientDetailsValidation', $_POST);
	return $errormessage;
}

function checkcontactdetails ($firstname, $lastname, $email, $address1, $city, $state, $postcode, $phonenumber)
{
	global $_LANG;
	if (!trim ($firstname))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorfirstname'];
	}

	if (!trim ($lastname))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorlastname'];
	}

	if (!trim ($email))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerroremail'];
	}
	else
	{
		if (!eregi ('' . '^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,6})$', $email))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerroremailinvalid'];
		}
	}

	$emaildomain = explode ('@', $email, 2);
	$emaildomain = $emaildomain[1];
	$result = select_query ('tblbannedemails', '', array ('domain' => $emaildomain));
	$data = mysql_fetch_array ($result);
	$banneddomainid = $data['id'];
	if ($banneddomainid)
	{
		update_query ('tblbannedemails', array ('count' => '+1'), array ('id' => $banneddomainid));
		$errormessage .= '<li>' . $_LANG['clientareaerrorbannedemail'];
	}

	if (!trim ($address1))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerroraddress1'];
	}

	if (!trim ($city))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorcity'];
	}

	if (!trim ($state))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorstate'];
	}

	if (!trim ($postcode))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorpostcode'];
	}
	else
	{
		if (ereg ('[^ A-Za-z0-9 -]', $postcode))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerrorpostcode2'];
		}
	}

	if (!trim ($phonenumber))
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorphonenumber'];
	}
	else
	{
		if (ereg ('[^ .0-9-]', $phonenumber))
		{
			$errormessage .= '<li>' . $_LANG['clientareaerrorphonenumber2'];
		}
	}

	if ($country == 'Select Country')
	{
		$errormessage .= '<li>' . $_LANG['clientareaerrorcountry'];
	}

	return $errormessage;
}

function addclient ($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, $password, $securityqid, $securityqans, $sendemail = 'on')
{
	global $CONFIG;
	global $remote_ip;
	$fullhost = gethostbyaddr ($remote_ip);
	$currency = (is_array ($_SESSION['currency']) ? $_SESSION['currency'] : getcurrency ('', $_SESSION['currency']));
	$password_hash = generateclientpw ($password);
	$table = 'tblclients';
	$array = array ('firstname' => $firstname, 'lastname' => $lastname, 'companyname' => $companyname, 'email' => $email, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'postcode' => $postcode, 'country' => $country, 'phonenumber' => $phonenumber, 'password' => $password_hash, 'lastlogin' => 'now()', 'securityqid' => $securityqid, 'securityqans' => encrypt ($securityqans), 'ip' => $remote_ip, 'host' => $fullhost, 'status' => 'Active', 'datecreated' => 'now()', 'language' => $_SESSION['Language'], 'currency' => $currency['id']);
	$uid = insert_query ($table, $array);
	logactivity ('' . 'Created Client ' . $firstname . ' ' . $lastname . ' - User ID: ' . $uid);
	if ($sendemail)
	{
		sendmessage ('Client Signup Email', $uid, array ('client_password' => $password));
	}

	$_SESSION['uid'] = $uid;
	if ($CONFIG['DisableSessionIPCheck'])
	{
		$haship = '';
	}
	else
	{
		$haship = $remote_ip;
	}

	$_SESSION['upw'] = md5 ($uid . $password_hash . $haship);
	run_hook ('ClientAdd', array ('userid' => $uid, 'firstname' => $firstname, 'lastname' => $lastname, 'companyname' => $companyname, 'email' => $email, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'postcode' => $postcode, 'country' => $country, 'phonenumber' => $phonenumber, 'password' => $password));
	run_hook ('ClientLogin', array ('userid' => $uid));
	return $uid;
}

function addcontact ($userid, $firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, $generalemails = '', $productemails = '', $domainemails = '', $invoiceemails = '', $supportemails = '')
{
	$table = 'tblcontacts';
	$array = array ('userid' => $userid, 'firstname' => $firstname, 'lastname' => $lastname, 'companyname' => $companyname, 'email' => $email, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'postcode' => $postcode, 'country' => $country, 'phonenumber' => $phonenumber, 'generalemails' => $generalemails, 'productemails' => $productemails, 'domainemails' => $domainemails, 'invoiceemails' => $invoiceemails, 'supportemails' => $supportemails);
	$contactid = insert_query ($table, $array);
	run_hook ('ContactAdd', $array);
	return $contactid;
}

function deleteclient ($userid)
{
	run_hook ('PreDeleteClient', array ('userid' => $userid));
	delete_query ('tblclients', array ('id' => $userid));
	delete_query ('tblcontacts', array ('userid' => $userid));
	$result = select_query ('tblhosting', 'id', array ('userid' => $userid));
	while ($data = mysql_fetch_array ($result))
	{
		$domainlistid = $data['id'];
		delete_query ('tblhostingaddons', array ('hostingid' => $domainlistid));
	}

	$result = select_query ('tblcustomfields', 'id', array ('type' => 'client'));
	while ($data = mysql_fetch_array ($result))
	{
		$customfieldid = $data['id'];
		delete_query ('tblcustomfieldsvalues', array ('fieldid' => $customfieldid, 'relid' => $userid));
	}

	$result = select_query ('tblcustomfields', 'id,relid', array ('type' => 'product'));
	while ($data = mysql_fetch_array ($result))
	{
		$customfieldid = $data['id'];
		$customfieldpid = $data['relid'];
		$result2 = select_query ('tblhosting', 'id', array ('userid' => $userid, 'packageid' => $customfieldpid));
		while ($data = mysql_fetch_array ($result2))
		{
			$hostingid = $data['id'];
			delete_query ('tblcustomfieldsvalues', array ('fieldid' => $customfieldid, 'relid' => $hostingid));
		}
	}

	delete_query ('tblorders', array ('userid' => $userid));
	delete_query ('tblhosting', array ('userid' => $userid));
	delete_query ('tbldomains', array ('userid' => $userid));
	delete_query ('tblemails', array ('userid' => $userid));
	delete_query ('tblinvoices', array ('userid' => $userid));
	delete_query ('tblinvoiceitems', array ('userid' => $userid));
	delete_query ('tbltickets', array ('userid' => $userid));
	delete_query ('tblaffiliates', array ('clientid' => $userid));
	delete_query ('tblnotes', array ('userid' => $userid));
	delete_query ('tblcredit', array ('clientid' => $userid));
	logactivity ('' . 'Client Deleted - ID: ' . $userid);
}

function getsecurityquestions ($questionid = '')
{
	if ($questionid)
	{
		$query = select_query ('tbladminsecurityquestions', '', array ('question' => $questionid));
	}
	else
	{
		$query = select_query ('tbladminsecurityquestions', '', '');
	}

	$results = array ();
	while ($data = mysql_fetch_assoc ($query))
	{
		$results[] = array ('id' => $data['id'], 'question' => decrypt ($data['question']));
	}

	return $results;
}

function checkpasswordstrength ($pw)
{
	global $CONFIG;
	global $_LANG;
	if ($CONFIG['RequiredPWStrength'])
	{
		$pwstrength = 0;
		$pwlength = $calcpwlength = strlen ($pw);
		if (5 < $pwlength)
		{
			$calcpwlength = 5;
		}

		$numnumeric = ereg_replace ('[^0-9]', '', $pw);
		$numeric = strlen ($numnumeric);
		if (3 < $numeric)
		{
			$numeric = 3;
		}

		$symbols = ereg_replace ('[^A-Za-z0-9]', '', $pw);
		$numsymbols = $pwlength - strlen ($symbols);
		if ($numsymbols < 0)
		{
			$numsymbols = 0;
		}

		if (3 < $numsymbols)
		{
			$numsymbols = 3;
		}

		$numupper = ereg_replace ('[A-Z]', '', $pw);
		$upper = $pwlength - strlen ($numupper);
		if ($upper < 0)
		{
			$upper = 0;
		}

		if (3 < $upper)
		{
			$upper = 3;
		}

		$pwstrength = $calcpwlength * 10 - 20 + $numeric * 10 + $numsymbols * 15 + $upper * 10;
		if ($pwstrength <= $CONFIG['RequiredPWStrength'])
		{
			return '<li>' . $_LANG['pwstrengthfail'];
		}
	}

}

function generateclientpw ($plain, $salt = '', $ignoreconfig = false)
{
	global $CONFIG;
	if (($CONFIG['NOMD5'] AND !$ignoreconfig))
	{
		$pw = encrypt ($plain);
	}
	else
	{
		if (!$salt)
		{
			$seeds = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#!%()#!%()#!%()';
			$seeds_count = strlen ($seeds) - 1;
			$i = 0;
			while ($i < 5)
			{
				$salt .= $seeds[rand (0, $seeds_count)];
				++$i;
			}
		}

		$pw = md5 ($salt . html_entity_decode ($plain)) . ':' . $salt;
	}

	return $pw;
}

?>